class RankListPanel extends BasePanel
{
    // 返回按钮
    public backBtn: eui.Image;
    // 查看群排行
    public shareBtn: eui.Image;

    private rankGroup:eui.Group;
    private listRect:eui.Rect;
    private mineRect:eui.Rect;

    private leftArrowImg:eui.Image;
    private rightArrowImg:eui.Image;

    private rankBox:eui.Group;

    public constructor(index: number) {
		super(index);
		this.skinName = "RankListPanelSkin";
        if(StringUtil.sdkVersionCompare(GameConfig.SDKVersion,"2.0.4")){
			this.rankBox.y = GameConfig.stageHeight-227-this.rankBox.height;
		}else{
			this.rankBox.y = (GameConfig.stageHeight-this.rankBox.height)/2;
		}
	}
    public viewWillAppear(){
        super.viewWillAppear();
        GameConfig.showBannerAd();
    }
    public viewWillDisAppear(){
        super.viewWillDisAppear();
        GameConfig.hideBannerAd();
    }
	public onChildrenCreated() {
		super.onChildrenCreated();
        let fromY = this.rankGroup.parent.y;
        let listRect = {x:(this.width-this.listRect.width)/2,
                        y:fromY+this.rankGroup.y+this.listRect.y,
                        width:this.listRect.width,
                        height:this.listRect.height};
        let mineRect = {x:(this.width-this.mineRect.width)/2,
                        y:fromY+this.rankGroup.y+this.mineRect.y,
                        width:this.mineRect.width,
                        height:this.mineRect.height};
        
        OpenDataUtil.showRank(this,{status: GameConfig.shareCavansCommand.SHOW_RANK,
                                    mine: UserData.getMineOpenData(),
                                    listRect:listRect,
                                    mineRect:mineRect,
                                    uiIndex: this.index});
	}
    /**
     * 点击加载上一页
     */
    private leftArrowClicked()
    {
        OpenDataUtil.postMessage({status: GameConfig.shareCavansCommand.PRE_PAGE_RANK,
                                    uiIndex: this.index});
    }
    /**
     * 点击加载下一页
     */
    private rightArrowClicked()
    {
        OpenDataUtil.postMessage({status: GameConfig.shareCavansCommand.NEXT_PAGE_RANK,
                                    uiIndex: this.index});
    }
    /**
     * 查看群排行
     */
    private async lookGroupRank() {
        // 策略F
		let query = {from:GameConfig.shareFrom.rankListPageSeeGroup2Share};
		let shareData = GameConfig.getShareData(GameConfig.shareInfoC,query);
		platform.shareAppMessage(shareData);
    }
    
    private backBtnClicked() {
        
        if(this.index == GameConfig.uiIndex.rankListFromHome){
            App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, this.index);
        }else if(this.index == GameConfig.uiIndex.rankListFromOver){
            App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, this.index);
            App.EventManager.dispatchEvent(GameConstants.UI_ADD_TO_PARENT,GameConfig.uiIndex.over);
        }else{
            this.parent.removeChild(this);
        }
		
    }
	/**添加监听 */
	public addListener(){
		super.addListener();
        this.backBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.backBtnClicked,this);
        this.shareBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lookGroupRank, this);
        this.leftArrowImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.leftArrowClicked, this);
        this.rightArrowImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.rightArrowClicked, this);
        
        
	}
	/**移除监听 */
	public removeListener(){
		super.removeListener();
        this.backBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.backBtnClicked,this);
        this.shareBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lookGroupRank, this);
        this.leftArrowImg.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.leftArrowClicked, this);
        this.rightArrowImg.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.rightArrowClicked, this);
        OpenDataUtil.cancleRank(this);
	}
	
}